package test2;

import java.util.HashMap;
import java.util.Map;

/**
 * @author sunkai
 * @date 2023/3/22 13:42
 */
public class Hash_Equel {
    private String name;

    public Hash_Equel(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) return false;
        if (!(obj instanceof Hash_Equel))
            return false;
        if (obj == this)
            return true;
        return this.name.equals(((Hash_Equel) obj).name);
    }

    @Override
    public int hashCode() {
        return this.name.hashCode();
    }


    public static void main(String[] args) {
        Hash_Equel a1 = new Hash_Equel("沉默王二");
        Hash_Equel a2 = new Hash_Equel("沉默王三");

        Map<Hash_Equel, Integer> m = new HashMap<Hash_Equel, Integer>();
        m.put(a1, 18);
        m.put(a2, 28);
        System.out.println(m.get(new Hash_Equel("沉默王二")));
    }
}
